package com.hzhk.happyrent.ui.adapter.bill;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.TextView;

import com.hzhk.happyrent.R;
import com.hzhk.happyrent.bean.bill.ProductPeriodsBean;
import com.hzhk.happyrent.ui.activity.bill.BillListActivity;
import com.hzhk.happyrent.ui.adapter.BaseAdapter;
import com.hzhk.happyrent.utils.glide.ShowImageUtils;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2018/1/24 0024.
 */

public class ProductPeriodsAdapter extends BaseAdapter<ProductPeriodsBean.DataBean.OrdersBean> {
    public ProductPeriodsAdapter(Context context) {
        super(context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.item_product_periods,
                    null);
            viewHolder = new ViewHolder(convertView);
            convertView.setTag(viewHolder);
        } else {
            viewHolder = (ViewHolder) convertView.getTag();
        }
        viewHolder.setData(getItem(position));
        return convertView;
    }



    class ViewHolder {
        @BindView(R.id.image_pro)
        ImageView imagePro;
        @BindView(R.id.product_title)
        TextView productTitle;
        @BindView(R.id.order_num)
        TextView orderNum;
        @BindView(R.id.order_rent_count)
        TextView orderRentCount;
        @BindView(R.id.order_rent_paid)
        TextView orderRentPaid;
        @BindView(R.id.tv_pay)
        TextView tvPay;
        @BindView(R.id.bt_pay)
        Button btPay;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }

        public void setData(final ProductPeriodsBean.DataBean.OrdersBean ordersBean) {
            ShowImageUtils.showImageView(mContext, imagePro, ordersBean.getGoodsImage());
            productTitle.setText(ordersBean.getGoodsName());
            orderNum.setText(ordersBean.getMainOrderSn());
            orderRentCount.setText(ordersBean.getZuDate()+"期");
            orderRentPaid.setText(ordersBean.getZuBackNum()+"期");
            tvPay.setText("￥"+ordersBean.getPrice());
            btPay.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View v) {
                    Intent intent=new Intent(mContext, BillListActivity.class);
                    intent.putExtra("order_id",ordersBean.getOrderId());
                    mContext.startActivity(intent);
                }
            });
        }
    }
}
